package com.magictower.primary.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.magictower.primary.R;
import com.magictower.primary.common.SPConstant;

/**
 * Created by kejunzhan on 2017/12/6.
 */

public class LostFindActivity extends AppCompatActivity {

    private SharedPreferences mPref;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lost_find);

        mPref = getSharedPreferences(SPConstant.CONFIG, MODE_PRIVATE);
        // 安全手机号是否设置
        String safePhone = mPref.getString(SPConstant.SAFE_PHONE, "");
        if (!TextUtils.isEmpty(safePhone)){
            // 设置手机号
            TextView tvSafePhone = (TextView) findViewById(R.id.tv_safe_phone);
            tvSafePhone.setText(safePhone);
            //设置小图标
            ImageView ivLock = (ImageView) findViewById(R.id.iv_lock);
            //设置文字显示
            TextView tvStatus = (TextView) findViewById(R.id.tv_status);
            Boolean isLock = mPref.getBoolean(SPConstant.SAFE_PROTECT, false);
            if (isLock) {
                tvStatus.setText("防盗已开启");
                ivLock.setImageResource(R.drawable.lock);
            } else {
                tvStatus.setText("防盗已关闭");
                ivLock.setImageResource(R.drawable.unlock);
            }
        } else {
            //进入向导页面
            reEnter(getCurrentFocus());
        }
    }

    /**
     * 进入重新设置向导
     *
     * @param view
     */
    public void reEnter(View view) {
        startActivity(new Intent(LostFindActivity.this, Setup1Activity.class));
        finish();
    }
}
